package com.easy.frame.servers.sys.controller;


import com.easy.frame.base.api.pojo.PageDTO;
import com.easy.frame.base.api.pojo.PageVO;
import com.easy.frame.base.basic.ServiceResponse;
import com.easy.frame.base.service.base.BaseController;
import com.easy.frame.servers.sys.dto.SysCodeDefDTO;
import com.easy.frame.servers.sys.entity.SysCodeDef;
import com.easy.frame.servers.sys.service.process.SysCodeDefService;
import com.easy.frame.servers.sys.vo.SysCodeDefVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 编码定义表相关接口类
 *
 * @author tp
 * @date 2021/1/5 10:39
 */
@Slf4j
@Api(tags = "编码定义/sys-code")
@RestController
@RequestMapping("/sys-code")
public class SysCodeDefController extends BaseController {

    @Autowired
    SysCodeDefService sysCodeDefService;

    @ApiOperation("分页")
    @PostMapping("/page")
    public ServiceResponse<PageVO<SysCodeDefVO>> page(@RequestBody PageDTO<SysCodeDefDTO> param) {
        PageVO<SysCodeDefVO> result = sysCodeDefService.selectForPage(param);
        return success(result);
    }

    @ApiOperation("查询-根据id")
    @GetMapping("/by/id")
    public ServiceResponse<SysCodeDefVO> getById(@ApiParam(value = "主键id", required = true)
                                                 @RequestParam Long id) {
        return success(sysCodeDefService.selectVOById(id));
    }

    @ApiOperation("保存")
    @PostMapping
    public ServiceResponse<SysCodeDef> save(@RequestBody SysCodeDef entity) {
        sysCodeDefService.save(entity);
        return success(entity);
    }

    @ApiOperation("修改-根据id")
    @PutMapping
    public ServiceResponse<SysCodeDef> update(@RequestBody SysCodeDef entity) {
        sysCodeDefService.updateEntityById(entity);
        return success(entity);
    }

    @ApiOperation("删除-根据id")
    @DeleteMapping("/by/id")
    public ServiceResponse<?> deleteById(@ApiParam("主键id") @RequestParam Long id) {
        sysCodeDefService.updateDeleted(id);
        return success();
    }

}
